package com.ruoyi.project.mahjong.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.mahjong.domain.DeskIng;
import com.ruoyi.project.mahjong.domain.MyConstat;
import com.ruoyi.project.mahjong.domain.TablePool;
import com.ruoyi.project.mahjong.domain.dto.PoolDto;
import com.ruoyi.project.mahjong.mapper.TablePoolMapper;
import com.ruoyi.project.mahjong.service.IDeskIngService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.mahjong.mapper.TReservationMapper;
import com.ruoyi.project.mahjong.domain.TReservation;
import com.ruoyi.project.mahjong.service.ITReservationService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 会员预约Service业务层处理
 *
 * @author ruoyi
 * @date 2023-07-18
 */
@Service
public class TReservationServiceImpl implements ITReservationService
{
    @Autowired
    private TReservationMapper tReservationMapper;
    @Autowired
    private TablePoolMapper tablePoolMapper;

    /**
     * 查询会员预约
     *
     * @param id 会员预约ID
     * @return 会员预约
     */
    @Override
    public TReservation selectTReservationById(Long id)
    {
        return tReservationMapper.selectTReservationById(id);
    }

    /**
     * 查询会员预约列表
     *
     * @param tReservation 会员预约
     * @return 会员预约
     */
    @Override
    public List<TReservation> selectTReservationList(TReservation tReservation)
    {
        return tReservationMapper.selectTReservationList(tReservation);
    }

    /**
     * 新增会员预约
     *
     * @param tReservation 会员预约
     * @return 结果
     */
    @Override
    public int insertTReservation(TReservation tReservation)
    {
        tReservation.setCreateTime(DateUtils.getNowDate());
        return tReservationMapper.insertTReservation(tReservation);
    }

    /**
     * 修改会员预约
     *
     * @param tReservation 会员预约
     * @return 结果
     */
    @Override
    public int updateTReservation(TReservation tReservation)
    {
        tReservation.setUpdateTime(DateUtils.getNowDate());
        return tReservationMapper.updateTReservation(tReservation);
    }

    /**
     * 批量删除会员预约
     *
     * @param ids 需要删除的会员预约ID
     * @return 结果
     */
    @Override
    public int deleteTReservationByIds(Long[] ids)
    {
        return tReservationMapper.deleteTReservationByIds(ids);
    }

    /**
     * 删除会员预约信息
     *
     * @param id 会员预约ID
     * @return 结果
     */
    @Override
    public int deleteTReservationById(Long id)
    {
        return tReservationMapper.deleteTReservationById(id);
    }

    @Override
    @Transactional
    public void loadupdatePool() {
        String time=DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,DateUtils.getNowDate());
        List<TReservation>  reservationList= tReservationMapper.loadpool(time, MyConstat.NO_LOAD);
        if(ObjectUtil.isNotEmpty(reservationList)) {
            for (TReservation reservation : reservationList) {
                TablePool pool = new TablePool();
                pool.setMemberId(reservation.getMemberId());
                List<TablePool> poolList = tablePoolMapper.selectTablePoolList(pool);
                if (ObjectUtil.isEmpty(poolList)) {
                    pool.setMemberName(reservation.getName());
                    pool.setState(MyConstat.MR_STATE);
                    pool.setBak2(reservation.getId().toString());
                    pool.setRemark(reservation.getRemark());
                    tablePoolMapper.insertTablePool(pool);
                }
            }
            for (TReservation reservation : reservationList) {
                reservation.setFlag(MyConstat.LOAD);
                tReservationMapper.updateTReservation(reservation);
            }

        }
    }

    /**
     * 根据陪桌人信息查询该桌的情况。
     * @param dto
     * @return
     */
    @Override
    public Map<String, Object> selectdetails(PoolDto dto) {

        return null;
    }
}
